﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace TrafficLightSim
{
    public enum Direction { Up, Down, Left, Right, TurnLeft, TurnRight };

    public class Car
    {
        #region Field region
        Vector2 position; //position of car, represented in points (x and y)
        float speed; //speed of the car
        float acceleration; //acceleration of car
        Vector2 size; //size area of the car
        Direction direction; //direction the car is moving
        Vector2 motion;
        bool willAppear;
        Rectangle boundRect; //a rectangle around the car, for collision detection
        bool canMove;
        bool overtake; // my changes
        Direction overtakeDirection;
        int overtakeDist;
        bool isInAccident;
        #endregion

        #region Property region

        public bool IsInAccident
        {
            get { return isInAccident; }
            set { isInAccident = value; }
        }

        public Direction OvertakeDirection
        {
            get { return overtakeDirection; }
            set { overtakeDirection = value; }
        }

        public int OvertakeDist
        {
            get { return overtakeDist; }
            set { overtakeDist = value; }
        }


        // my changes
        public bool Overtake
        {
            get { return overtake; }
            set { overtake = value; }
        }
        // my changes

        public float Acceleration
        {
            get { return acceleration; }
            set { acceleration = value; }
        }

        public bool CanMove
        {
            get { return canMove; }
            set { canMove = value; }
        }

        public Rectangle BoundRect
        {
            get { return boundRect; }
            set { boundRect = value; }
        }

        public bool WillAppear
        {
            get { return willAppear; }
            set { willAppear = value; }
        }

        public Direction Direction
        {
            get { return direction; }
            set { direction = value; }
        }

        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        public float Speed
        {
            get { return speed; }
            set { speed = value; }
        }

        public Vector2 Size
        {
            get { return size; }
            set { size = value; }
        }
        #endregion

        #region Constructor region

        public Car()
        {
            speed = 4f;
            position.X = -50;
            position.Y = 200;
            //direction = Direction.Right;
            canMove = true;
            overtake = false;
            isInAccident = false;
        } //empty constructor

        public Car(Vector2 point)
        {
            position = point; //constructor that takes in the coordinate of the car
            speed = 4f;
        }
        #endregion

        #region Method Region

        public void MoveCar()
        {
            if (direction == Direction.Down)
            {
                motion.Y = speed;
            }
            else if (direction == Direction.Right)
            {
                motion.X = speed;
            }
            else if (direction == Direction.Up)
            {
                motion.Y = -speed;
            }
            else if (direction == Direction.Left)
            {
                motion.X = -speed;
            }
            else if (direction == Direction.TurnRight)
            {
                motion.X = speed;
                motion.Y = -speed;
            }
            else if (direction == Direction.TurnLeft)
            {
                motion.X = -speed;
                motion.Y = speed;
            }

            motion.Normalize();
            position += motion * speed; //change the car position
            boundRect = new Rectangle((int)position.X, (int)position.Y, (int)size.X, (int)size.Y); //for collision purpose
        }

        // my changes
        public void moveRectangle(int x, int y)
        {
            boundRect.X += x;
            boundRect.Y += y;
        }

        #endregion
    }
}
